package com.tungse.juc.cas;

import java.util.concurrent.atomic.AtomicInteger;

public class WhatIsCAS {

    //Compare and Swap 比较并交换
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(0);
        //如果期望的值达到了， 那么就更新， 否则不更新， 返回是否更新成功
        System.out.println(atomicInteger.compareAndSet(0, 2));
        System.out.println(atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(0, 2));
        System.out.println(atomicInteger.get());

    }
}
